<?php defined('SYSPATH') OR die('No direct access allowed.'); ?>

	<script type="text/javascript">
	 	dojo.require("dijit.Editor");
		dojo.require("dijit.form.ValidationTextBox");
		dojo.require("dijit.form.FilteringSelect");
		dojo.require("dijit.form.DateTextBox");
		dojo.require("dijit.form.RadioButton");
		dojo.require("dojox.validate.regexp");
		dojo.require("dojo.parser");
	</script>
		
	<script type="text/javascript">
		$(document).ready(function() {
			$("input[name='btnCancel']").click(function() {
				var uri = ISS.lang.getBasePath()+'index.php';
				window.location = uri;
			});
		}); 
	</script>
	
	<?php 	
	if (!empty($form['txtPicture'])) {
		echo html::Stylesheet(
			array
			(
				'media/css/register_picture_block.css',
			),
			array
			(
				'screen',
			)
		);	
	}
	else {
		echo html::Stylesheet(
			array
			(
				'media/css/register_block.css',
			),
			array
			(
				'screen',
			)
		);	
	}
	?>
		
<div id="mainCont">
	<?php print form::open_multipart('member/register/save');?>
		<div id="registerBlock">
			<div id="registerBlockTop"> 
				<h3>สมัครสมาชิก</h3>
				<p><?php echo (empty($status)) ? 'กรุณากรอกข้อมูลให้ครบสมบูรณ์' : $status;?></p>
			</div>
			<div id="registerBlockBody">
				<table>
					<tr>
						<td><div class="mandatory">ชื่อ::</div></td>
						<td>
							<select style="width:80px"
								dojoType="dijit.form.FilteringSelect"
								value="<?php echo html::specialchars($form['cboPrefix']) ?>"
								name="cboPrefix"
							    required="true"								
								invalidMessage="กรณาระบุคำนำหน้า"
								autoComplete="true">
								<?php foreach ($master_prefixs as $prefix): ?>
								<option value="<?php echo $prefix['id']; ?>"><?php echo html::specialchars($prefix['title']); ?></option>
							    <?php endforeach ?>							
							</select>
													
							<input type="text" name="txtFirstname" value="<?php echo html::specialchars($form['txtFirstname']) ?>"/>
							<input type="text" name="txtLastname" value="<?php echo html::specialchars($form['txtLastname']) ?>"/>
						</td>
					</tr>
					
					<tr>
						<td>วันเกิด::</td>
						<td>
							<input id="txtBirthdate" type="text" name="txtBirthdate" value="<?php echo html::specialchars($form['txtBirthdate']) ?>"
								dojoType="dijit.form.DateTextBox"
							/>
						</td>
					</tr>
					<tr>
						<td><div class="mandatory">เพศ::</div></td>
						<td>
							<?php foreach ($master_sexs as $sex): ?>
								<input type="radio" name="rdoSex" dojoType="dijit.form.RadioButton" value="<?php echo $sex['id'];?>" 
								<?php
									if (empty($form['rdoSex'])) { 
										echo ($sex['id']==1)? 'checked="checked"' : '';
									}
									else {
										echo ($sex['id']==$form['rdoSex'])? 'checked="checked"' : '';
									} 
								?>>
								<?php echo html::specialchars($sex['title']); ?>
								</input>
							<?php endforeach ?>
						</td>
					</tr>
					<tr>
						<td><div class="mandatory">ชื่อเข้าระบบ::</div></td>
						<td>
							<input type="text" name="txtUsername" value="<?php echo html::specialchars($form['txtUsername']) ?>"/>
						</td>
					</tr>
					<tr>
						<td><div class="mandatory">รหัสผ่าน::</div></td>
						<td>
							<input type="password" name="txtPassword" value="<?php echo html::specialchars($form['txtPassword']) ?>"/>
						</td>
					</tr>
					<tr>
						<td><div class="mandatory">email::</div></td>
						<td>
							<input type="text" 
								name="txtEmail" 
								value="<?php echo html::specialchars($form['txtEmail']) ?>"
								id="txtEmail" 
								size="30" 
								dojoType="dijit.form.ValidationTextBox" 
								regExp=".*@.*"/>
						</td>
					</tr>
					<tr>
						<td>คำถามกันลืมรหัสผ่าน::</td>
						<td>
							<select
								dojoType="dijit.form.FilteringSelect"
								name="cboQuestion"
								value="<?php echo html::specialchars($form['cboQuestion']) ?>"
								invalidMessage="กรณาระบุคำถามกันลืม"
								autoComplete="true">
								<?php foreach ($master_questions as $question): ?>
								<option value="<?php echo $question['id']; ?>"><?php echo html::specialchars($question['title']); ?></option>
							    <?php endforeach ?>							
							</select>						
						</td>
					</tr>
					<tr>
						<td>คำตอบ::</td>
						<td>
							<input type="text" name="txtAnswer" value="<?php echo html::specialchars($form['txtAnswer']) ?>"/>
						</td>
					</tr>
					<tr>
						<td><div class="mandatory">ประเภทสมาชิก::</div></td>
						<td>
							<?php foreach ($master_member_types as $member_type): ?>
								<input type="radio" name="rdoMemberType" dojoType="dijit.form.RadioButton" value="<?php echo $member_type['id']; ?>" 
								<?php 
									
									if (empty($form['rdoMemberType'])) { 
										echo ($member_type['id']==1)? 'checked="checked"' : ''; 
									}
									else {
										echo ($member_type['id']==$form['rdoMemberType'])? 'checked="checked"' : '';
									} 
								?>>
								<?php echo html::specialchars($member_type['title']); ?>
								</input>
							<?php endforeach ?>						
						</td>
					</tr>
					<tr>
						<td><div class="mandatory">รหัสยืนยัน::</div></td>
						<td><?php echo $captcha->render();?></td>
					</tr>	
					<tr>
						<td></td>
						<td><input type="text" name="txtCaptcha" value="<?php echo html::specialchars($form['txtCaptcha']) ?>"></input></td>
					</tr>			
					<tr>
						<td>รูปภาพ::</td>
						<td>
							<?php
								if (!empty($form['txtPicture'])) {
									echo '<img id=imgPicture  alt="'. html::specialchars($form['txtUsername']) .'" src="'. url::base() . html::specialchars($form['txtPicture']) .'" />';
									echo '<br/>';
								} 
								$attributes = array('name' => 'txtPicture');
								echo form::upload($attributes, '');	
							?>
						</td>
					</tr>
				</table>
			</div>
			<div id="registerBlockBot">
				<input type="submit" id="btnSave" name="btnSave" value="บันทึก" />
				<input type="button" id="btnCancel" name="btnCancel" value="ยกเลิก" />
			</div>
		</div>
	<?php print form::close(); ?>
	<div id="registerError">
		<?php 
		echo "<div id='errName' class='registerBlockError'>";
		foreach ($errors as $error):
			echo html::specialchars($error); 
			echo '<br/>';
		endforeach; 
		echo "</div>";
		?>				
	</div>
</div>
